import axios from  'axios';


let http = {
	post(url,callback,params={}){
		console.log("params:",params)
		let urlSeachParames = new URLSearchParams();
		for(let key in params){
			
			console.log("key:",key)
			urlSeachParames.append(key,params[key])
		}

		axios.post(url,urlSeachParames).
		then((ret)=>{
		
			if(ret.status == 200){ //网络请求是通的，axios的状态
				let response = ret.data;//响应结果
				let {code ,msg ,data} = response;
				if(code == 200){
					callback(data)
				}else{
					alert("出错了:"+msg)
				}
			}
			
		})
	},
	get(url,callback,params={}){
		//'/api/channel?_type=queryById&id='+this.id
		axios.get(url,{
			params:params
		}).
		then((ret)=>{
			if(ret.status == 200){ //网络请求是通的，axios的状态
				let response = ret.data;//响应结果
				let {code ,msg ,data} = response;
				if(code == 200){
					callback(data);
				}else{
					alert("出错了:"+msg)
				}
			}
			
		})
	}
}

export default http